package com.blog.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.blog.dao.ArticleMapper;
import com.blog.dao.MessageMapper;
import com.blog.model.Message;
import com.blog.service.interfaces.IMessageService;

@Service("messageService")
public class MessageService implements IMessageService {
	@Autowired
	MessageMapper messageMapper;
	@Autowired
	UserService userService;
	
	//接收者的所有信息
    public List<Message> selectByUserId(Integer id){
    	return messageMapper.selectByUserId(id);
    }
    
	//接收者的部分信息
    public Map<Message,String> selectByUserIdLimit(Integer id,Integer limit){
    	List<Message> limitMessage=messageMapper.selectByUserId(id);
    	Map<Message,String> result=new LinkedHashMap<Message,String>();
    	if(limitMessage.size()!=0){
    	for(int u=0;u<(limitMessage.size()>=limit?limit:limitMessage.size());u++){
    		System.out.println(limitMessage.size());
    		System.out.println(limitMessage.get(u));
    		System.out.println(limitMessage.get(u).getMfrom());
    		System.out.println(userService.getUserById(limitMessage.get(u).getMfrom()));
    		result.put(limitMessage.get(u),userService.getUserById(limitMessage.get(u).getMfrom()).getUsername());
    		
    	}
    	return result;}else{
    		return null;
    	}
    }
    
    //+
    public int insertSelective(Message record){
    	return messageMapper.insertSelective(record);
    }
	
}
